package com.example.androidtest.demo1

import java.util.*
import kotlin.jvm.Synchronized
import kotlin.Throws

class Ticket {
    private var count = 0
    private val queue: Queue<Int> = ArrayDeque()
    @Synchronized
    fun addTicket(name: String) {
        queue.offer(count++)
        println("${name}制造了$count 号票")
    }

    @Synchronized
    @Throws(InterruptedException::class)
    fun sealTicket(name: String) {
//        if (queue.isEmpty()) {
//            return
//        }
        Thread.sleep(100000)
        println("${name}买走了${queue.poll()}号票")
    }
}